// components/home/index.js


var app = getApp();
Component({
  properties: {
    isLogin: {
      type: Boolean,
      value: true,
    }
},
  data: {
  },
  attached:function(){
  },
  methods: {
    hideLogin: function() {
      this.setData({
        isLogin: true
      });
  },

  goLoginPage: function() {
      wx.navigateTo({
          url: "/pages/login/login"
      });
  },

  getPhoneNumber:function(e){
      var detail = e.detail, cache_key = wx.getStorageSync('cache_key'),that=this;
      if (detail.errMsg =='getPhoneNumber:ok'){
        if (!cache_key){
          app.globalData.token='';
          app.globalData.isLog=false;
          return false;
        }
        app.basePost(app.U({ c: 'user_api', a: 'bind_mobile' }), { 
          iv: detail.iv,
          cache_key: cache_key, 
          encryptedData: detail.encryptedData
        },function(res){
            that.hideLogin();
          that.setData({ 'userInfo.phone': res.data.phone});
           app.Tips({ title: res.msg, icon: 'success' });
           app.globalData.userPhone = res.data.phone;
          //  setTimeout(function () { wx.navigateBack({ delta: 1 }) }, 1200)
         
        },function(res){
          return app.Tips({ title: '绑定失败'});
        });
      }else{
        app.Tips({ title:'取消授权'});
      }
    },
  }
})